﻿using HandyControl.Controls;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;

namespace AgileLogistics.View.User
{
    /// <summary>
    /// AddUser.xaml 的交互逻辑
    /// </summary>
    public partial class EditUser : System.Windows.Window
    {
        ViewModel.UserViewModel vm;

        Model.DBContext dbContext = new Model.DBContext();
        Model.Repository<Model.Users> RepUser = new Model.Repository<Model.Users>();
        public EditUser()
        {
            InitializeComponent();

            vm = DataContext as ViewModel.UserViewModel;

            //
           
            vm.DepList = dbContext.DB.Queryable<Model.Depment>().ToList();
           



        }

        private void btn_cancel_Click(object sender, RoutedEventArgs e)
        {
            this.Close();
        }

        private void btn_Save_Click(object sender, RoutedEventArgs e)
        {
           

            if(txt_psd.Password !=txt_psdRe.Password)
            {
                Growl.SuccessGlobal("两次密码输入不一致！");
                return;
            }else
            {
                vm.CurrUser.Password = txt_psd.Password;
            }
            dbContext.DB.Updateable<Model.Users>(vm.CurrUser).ExecuteCommand();

            Growl.SuccessGlobal("保存成功！");
            vm.UserList = new System.Collections.ObjectModel.ObservableCollection<Model.Users>(RepUser.GetList());
            this.Close();
        }
    }
}
